﻿using System.ComponentModel;
using System.Xml.Serialization;
using com.woodsoft.core.Files;
using com.woodsoft.core;
using EQ1.Objects;

namespace EQ1.Elements {
  public class RGB : UIClass , IUIElement<RGB> {
    public RGB ( UIDocument doc , string name )
      : base( doc , name ) {
      this.R = 0;
      this.G = 0;
      this.B = 0;
      this.Alpha = 255;
    }
    public RGB ( UIDocument doc )
      : this( doc , "RGB" ) {
    }

    #region IUIElement<ButtonDrawTemplate> Members

    public void Copy ( RGB val ) {
      base.Copy( val );

      this.R = val.R;
      this.G = val.G;
      this.B = val.B;
      this.Alpha = val.Alpha;
    }
    public void Validate ( RGB val , string name ) {
      UIClass par = ( UIClass ) this.ParentNode;

      if( val.LocalName != name ) {
        RGB el = new RGB( ( UIDocument ) val.OwnerDocument , name );
        el.Copy( val );
        val = el;
      }

      if( par.GetElement( name ) != null )
        par.RemoveElement( name );

      par.AppendChild( val );
    }

    #endregion
    
    public int Alpha {
      get {
        return int.Parse( this.GetElement( "Alpha" ).InnerText );
      }
      set {
        if( this.GetElement( "Alpha" ) == null )
          this.AddElement( "Alpha" , value.ToString() );
        else
          this.GetElement( "Alpha" ).InnerText = value.ToString();
      }
    }
    public int R {
      get {
        return int.Parse( this.GetElement( "R" ).InnerText );
      }
      set {
        if( this.GetElement( "R" ) == null )
          this.AddElement( "R" , value.ToString() );
        else
          this.GetElement( "R" ).InnerText = value.ToString();
      }
    }
    public int G {
      get {
        return int.Parse( this.GetElement( "G" ).InnerText );
      }
      set {
        if( this.GetElement( "G" ) == null )
          this.AddElement( "G" , value.ToString() );
        else
          this.GetElement( "G" ).InnerText = value.ToString();
      }
    }
    public int B {
      get {
        return int.Parse( this.GetElement( "B" ).InnerText );
      }
      set {
        if( this.GetElement( "B" ) == null )
          this.AddElement( "B" , value.ToString() );
        else
          this.GetElement( "B" ).InnerText = value.ToString();
      }
    }


  }
}
